<template>
  <lay-col :md="24">
    <div class="qy-cat">
      <ul>
        <li @click="handleClick(0)" :class="{ qycaton: 0 == selectedKeys }">
          <lay-badge type="dot" :color="0 == selectedKeys ? 'orange' : '#c2c2c2'" ripple></lay-badge><a> 全部类别</a>
        </li>
        <li v-for="item in listData " @click="handleClick(item.id)" :class="{ qycaton: item.id == selectedKeys }">
          <lay-badge type="dot" :color="item.id == selectedKeys ? 'orange' : '#c2c2c2'" ripple></lay-badge>
          <a> {{ item.cateName }}</a>
        </li>
      </ul>
    </div>
  </lay-col>
</template>

<script lang="ts" name="AppCatList" setup>
import { ref } from "vue";
import { getCateListAll } from "../../../../api/module/content/applink"
import { AppLinkCate } from '../../../../types/applink'
const listData = ref({ targetList: <AppLinkCate><unknown>[], })
getCateListAll().then((res) => {
  if (res.status == 1) {
    listData.value = res.data.data
  }
})
const selectedKeys = ref(0)

// 与父组件的交互逻辑
const emits = defineEmits(['node-click']);
const handleClick = (id: number) => {
  emits('node-click', { id: id });
  selectedKeys.value = id
}
</script>
<style scoped>
.qy-cat {
  margin: auto;
  padding: 10px;
}

.qy-cat li {
  height: 30px;
  line-height: 30px;
  padding-left: 10px;
  width: 100%;
}

.qy-cat li a:hover {
  cursor: pointer;
}

.qycaton {
  background-color: #1E9FFF;
}

.qycaton a {
  color: #fff;
}
</style>